home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_386 / xlispstat / src2.lzh / XLisp-Stat / gamln.c < prev    next >
C/C++ Source or Header  |  1990-10-04  |  926b  |  44 lines

  1. /* log gamma function from Numerical Recipes */
  2. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  3. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  4. /* You may give out copies of this software; for conditions see the    */
  5. /* file COPYING included with this distribution.                       */
  6.  
  7. #include "xlisp.h"
  8. #include "osdef.h"
  9. #ifdef ANSI
  10. #include "xlsproto.h"
  11. #else
  12. #include "xlsfun.h"
  13. #endif ANSI
  14.  
  15. static double cof[6] = {
  16.    76.18009173,
  17.   -86.50532033,
  18.    24.01409822,
  19.    -1.231739516,
  20.     0.120858003e-2,
  21.    -0.536382e-5
  22. };
  23.  
  24. double gamma(xx)
  25.     double xx;
  26. {
  27.   double x, tmp, ser;
  28.   int j;
  29.   
  30.   if (xx < 1.0) return(gamma(1.0 + xx) - log(xx));
  31.   else {
  32.     x = xx - 1.0;
  33.     tmp = x + 5.5;
  34.     tmp -= (x + 0.5) * log(tmp);
  35.     ser = 1.0;
  36.     for (j = 0; j < 6; j++) {
  37.       x += 1.0;
  38.       ser += cof[j] / x;
  39.     }
  40.     return(-tmp + log(2.50662827465 * ser));
  41.   }
  42. }
  43.  
  44.